cmake_minimum_required(VERSION 3.8)
project(driver)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(diagnostic_msgs REQUIRED)
find_package(agv_msgs REQUIRED)
find_package(agv_srvs REQUIRED)
find_package(serial REQUIRED)
find_package(socketcan_interface REQUIRED)
find_package(common REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread) 

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

include_directories(
  include
  include/motor
  include/encoder
  include/comm
  ${socketcan_interface_INCLUDE_DIRS}
  ${serial_INCLUDE_DIRS}
)

file(GLOB COMM_SRCS
  "src/comm/*.cpp"
)

file(GLOB ENCODER_SRCS
  "src/encoder/*.cpp"
)

file(GLOB MOTOR_SRCS
  "src/motor/*.cpp"
)

add_library(comm SHARED
  ${COMM_SRCS}
)

target_link_libraries(comm
  ${serial_LIBRARIES}
  ${socketcan_interface_LIBRARIES}
  rclcpp::rclcpp
)

add_library(encoder SHARED
  ${ENCODER_SRCS}
) 

target_link_libraries(encoder  
  Boost::thread
)

ament_target_dependencies(encoder
  std_msgs
  serial
  rclcpp
)

add_library(motor SHARED
  ${MOTOR_SRCS}
)

ament_target_dependencies(motor 
  rclcpp 
  std_msgs
  agv_srvs
  agv_msgs
)

install(TARGETS 
  comm 
  encoder 
  motor 
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(DIRECTORY 
  include/
  DESTINATION include/${PROJECT_NAME}
)

ament_export_dependencies(
  rclcpp
  std_msgs
  agv_msgs
  agv_srvs
  serial
  socketcan_interface
  common
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include/driver)
ament_export_libraries(comm encoder motor)
ament_package()
